<?php
$translator = \Velacolib\Utility\Utility::translate();
use Zend\Session\Container;

$user_session = new Container('user');
?>
<link rel="stylesheet" href="<?php echo $this->basePath(); ?>/templates/front/css/topic_add.css">
<div class="page-header" id="banner" style="text-align: center">
    <h3>Đăng tin bước 2</h3>
</div>
<div class="content-body" style="min-height: 500px">


    <div class="row" style="margin-top: 20px;margin-bottom: 20px">
        <div class="col-sm-8 col-lg-8 col-md-8">
            Mời bạn chọn
            <select id="type_reg" class="input-lg">
                <option>Hình thức đăng ký</option>
                <option value="khach">Đăng như là khách</option>
                <option value="dangky">Đăng ký</option>
                <option value="dangnhap">Đăng nhập</option>
            </select>

            <div id="wrap_reg">

                <!-- dang tin nhu la khach -->

                <div id="khach" style="display: none">
                    <fieldset id="field-userinfo" style="margin-top: 20px;margin-bottom: 20px">
                        <legend><?= $translator->translate('Contact info') ?></legend>
                        <form action="/raovat/dangtin-buoc2" method="post" accept-charset="utf-8"
                              class="form require-validate">
                            <div class="form-group group_validate">
                                <label><?= $translator->translate('Fullname') ?></label>
                                <input req="true" type="text" name="name" id="ten" class="form-control input-sm"
                                       placeholder="">
                            </div>
                            <div class="form-group group_validate">
                                <label>Email</label>
                                <input req="true" type="text" name="email" id="email" class="form-control input-sm email_validate"
                                       placeholder="">
                            </div>
                            <div class="form-group group_validate">
                                <label><?= $translator->translate('Phone') ?></label>
                                <input req="true" type="text" name="phone" id="phone" class="form-control input-sm"
                                       placeholder="">
                            </div>
                            <div class="form-group group_validate">
                                <label><?= $translator->translate('Address') ?></label>
                                <input req="true" type="text" name="address" id="address" class="form-control input-sm"
                                       placeholder="">
                                <input type="hidden" name="login" value="false">
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-danger" id="submit">
                                    <?= $translator->translate('Post') ?>
                                </button>
                            </div>
                        </form>
                    </fieldset>
                </div>


                <!-- dang ky user + dang tin -->
                <div id="dangky" style="display: none">
                    <fieldset id="field-userinfo" style="margin-top: 20px;margin-bottom: 20px">
                        <legend><?= $translator->translate('Contact info') ?></legend>
                        <form action="/raovat/dangtin-buoc2" method="post" name="topic_add" accept-charset="utf-8"
                              class="form require-validate ">
                            <div class="form-group group_validate">
                                <label><?= $translator->translate('Fullname') ?></label>
                                <input req="true" type="text" name="name" id="ten" class="form-control input-sm"
                                       placeholder="">
                            </div>
                            <div class="form-group group_validate">
                                <label>Email</label>
                                <input req="true" type="email" name="email" id="emails" class="form-control input-sm email_validate"
                                       placeholder="">
                            </div>
                            <div class="form-group group_validate">
                                <label>Mật khẩu</label>
                                <input req="true" type="password" name="password" id="password"
                                       class="form-control input-sm"
                                       placeholder="">
                            </div>
                            <div class="form-group group_validate">
                                <label><?= $translator->translate('Phone') ?></label>
                                <input req="true" type="text" name="phone" id="phone" class="form-control input-sm"
                                       placeholder="">
                            </div>
                            <div class="form-group group_validate">
                                <label><?= $translator->translate('Address') ?></label>
                                <input req="true" type="text" name="address" id="address" class="form-control input-sm"
                                       placeholder="">
                                <input type="hidden" name="login" value="false">
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-danger" id="submit">
                                    <?= $translator->translate('Post') ?>
                                </button>
                            </div>
                        </form>
                    </fieldset>
                </div>

                <!-- dang nhaop roi dang tin -->

                <div id="dangnhap" style="display: none">
                    <fieldset id="field-userinfo" style="margin-top: 20px;margin-bottom: 20px">
                        <legend><?= $translator->translate('Login') ?></legend>
                        <form action="/raovat/dangtin-buoc2" method="post" name="topic_add" accept-charset="utf-8"
                              class="form require-validate">
                            <div class="form-group group_validate">
                                <label>Email</label>
                                <input req="true" type="text" name="username" id="username" class="form-control input-sm"
                                       placeholder="">
                            </div>

                            <div class="form-group group_validate">
                                <label><?= $translator->translate('Password') ?></label>
                                <input req="true" type="text" name="password" id="password"
                                       class="form-control input-sm" placeholder="">
                                <input type="hidden" name="login" value="true">
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-danger" id="submit">
                                    <?= $translator->translate('Post') ?>
                                </button>
                            </div>

                        </form>
                    </fieldset>
                </div>
            </div>

        </div>

        <div class="col-sm-4 col-lg-4 col-md-4 ">


        </div>
    </div>

</div>
<script>
    $(document).ready(function () {
        $("#type_reg").on('change', function () {
            var name_html = $(this).val();
            if (name_html == 'khach') {
                $("#khach").show();
                $("#dangnhap").hide();
                $("#dangky").hide();
            }
            if (name_html == 'dangky') {
                $("#dangky").show();
                $("#khach").hide();
                $("#dangnhap").hide();
            }
            if (name_html == 'dangnhap') {
                $("#dangnhap").show();
                $("#khach").hide();
                $("#dangky").hide();
            }
        });
        $('input.email_validate').on('blur',function(){
           var email = $(this).val();
           var id = $(this).attr('id');
            $.ajax({
                url: '/raovat/validate-email',
                type: 'POST',
                data: {email:email},
                dataType: 'html',
                beforeSend: function () {
                    $(".overlay-loading").fadeIn(500);
                },
                success: function (response) {
                     response = JSON.parse(response);
                    if(response.result ==false){
                       $("#"+id).val('').css('color',' #d2322d');
                        $("#"+id).attr("placeholder", response.message);
                        $("#"+id).focus();
                    }

                },
                error: function () {
                    jerror('Request timeout');
                    $(".overlay-loading").fadeOut(1000);
                }
            })
        })  ;
    });

</script>
